package cn.enjoy.rabbitmq.handler.boot;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Slf4j
@Component
@RabbitListener(queues = "direct.queue.2")
public class DriectQueueHandler2 {

    @RabbitHandler
    public void fanoutHandlerManualAck(Map msg, Message message, Channel channel) {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            log.info("direct 路由模式，direct.queue.2接收到的消息为：{}", msg.toString());
            channel.basicAck(deliveryTag, false);
//            Thread.sleep(10000);
        } catch (Exception e) {
            try {
                channel.basicRecover();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

}
